/*
   @Copyright:LeetCode
   @Author:   tjyemail
   @Problem:  http://leetcode.com/problems/roman-to-integer
   @Language: C++
   @Datetime: 19-05-22 15:11
   */

class Solution {
public:
	int romanToInt(string &s) {
		unordered_map<char,int> romans={{'I',1},{'V',5},{'X',10},
			{'L',50},{'C',100},{'D',500},{'M',1000}};
		int res=0;
		for(int i=s.size(); i--;){
			if(i+1<s.size() && romans[s[i]]<romans[s[i+1]])
				res-=romans[s[i]];
			else res+=romans[s[i]];
		}
		return res;
	}
};
